package com.astar.service.impl;

import com.astar.entity.CustomChapter;
import com.astar.entity.CustomUser;
import com.astar.entity.PractiseCourseChapter;
import com.astar.entity.PractiseCourseType;
import com.astar.mapper.PractiseCourseChapterMapper;
import com.astar.service.IPractiseCourseChapterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 分类练习-科目-章节表  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-01-31
 */
@Service
public class PractiseCourseChapterServiceImpl extends ServiceImpl<PractiseCourseChapterMapper, PractiseCourseChapter> implements IPractiseCourseChapterService {

    @Autowired
    HttpServletRequest request;

    @Autowired
    private PractiseCourseChapterMapper practiseCourseChapterMapper;


    @Override
    public List<CustomChapter> selectAll(CustomChapter customChapter) {
        return practiseCourseChapterMapper.selectLists(customChapter);
    }

    @Override
    public List<PractiseCourseType> selectCourse() {
        return practiseCourseChapterMapper.selectCourse();
    }

    @Override
    public int add(PractiseCourseChapter practiseCourseChapter) {
        practiseCourseChapter.setStatus("N");

        HttpSession session= request.getSession();
        List<CustomUser> user = (List<CustomUser>) session.getAttribute("menus");
        practiseCourseChapter.setCreatedBy(user.get(0).getLoginName());
        LocalDateTime localDateTime3 = LocalDateTime.now();
        practiseCourseChapter.setCreatedTime(localDateTime3);
        return practiseCourseChapterMapper.insert(practiseCourseChapter);
    }

    @Override
    public int deleteForIds(PractiseCourseChapter practiseCourseChapter) {
        practiseCourseChapter.setStatus("N");
            return practiseCourseChapterMapper.updateById(practiseCourseChapter);
    }

    @Override
    public PractiseCourseChapter selectForId(Integer id) {
        return practiseCourseChapterMapper.selectById(id);
    }

    @Override
    public int updateForId(PractiseCourseChapter practiseCourseChapter) {
        return practiseCourseChapterMapper.updateById(practiseCourseChapter);
    }
}
